<?php
require_once './Model/Blogg.php';
require_once './Model/Blogglist.php';
require_once ('./Controller/NewPostController.php');
class NavigationView 
{
	private static $PostId = "postId";
	
	public static function isViewingPost()
	{
		if (isset($_GET[self::$PostId]))
		{
			return true;
		}
		else 
		{
			return false;		
		}	
	}
	public static function getPostList()
	{
		return"?";
	}
	public static function getPostLink(Blogg $blogg)
	{
		return"?". self::$PostId. "=" . $blogg->getPostId();
	}
	public static function getSelectedPost(Blogglist $blogglist, Database $db)
	{
		if (isset($_GET[self::$PostId]))
		{
			$urlId = $_GET[self::$PostId];
			if ($urlId != "0" && intval($urlId)== 0)
				{
					throw new Exception("getSelectedPost() url format failure");
				}
				else 
				{
					$postId = intval($urlId);
					return $blogglist->getPostByID($postId, $db);	
				}
		}
		else
		{
			throw new Exception("GetSelectedPost() can only be called when viewing post");
		}
	}
}
